﻿<sap:ActivityDesigner x:Class="Vision.Core.ActivityComponents.Sql.DbQueryScalarDesigner"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    xmlns:sd="clr-namespace:System.Data;assembly=System.Data"
    xmlns:sap="clr-namespace:System.Activities.Presentation;assembly=System.Activities.Presentation"
    xmlns:sapv="clr-namespace:System.Activities.Presentation.View;assembly=System.Activities.Presentation"
    xmlns:sapc="clr-namespace:System.Activities.Presentation.Converters;assembly=System.Activities.Presentation"
    Collapsible="True">
    <sap:ActivityDesigner.Resources>
        <sapc:ArgumentToExpressionConverter x:Uid="sapv:ArgumentToExpressionConverter_1" x:Key="argumentToExpressionConverter" />

        <DataTemplate x:Key="CollapsedActivityViewTemplate">
            <Label Padding="0,0,0,0" FontStyle="Italic" Foreground="{x:Static SystemColors.GrayTextBrush}" HorizontalAlignment="Center" VerticalAlignment="Center">Double-click to view</Label>
        </DataTemplate>

        <DataTemplate x:Key="ExpandedActivityViewTemplate">
            <StackPanel>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                        <RowDefinition Height="24" />
                    </Grid.RowDefinitions>

                    <!-- Inputs Header -->
                    <TextBlock Grid.Row="0" Grid.ColumnSpan="2" x:Uid="Header_1" Text="Input(s):" FontWeight="Bold" Foreground="Navy" Margin="0,0,0,3" />

                    <!-- ModelItem.ConfigName -->
                    <TextBlock Grid.Row="1" Text="Config name:" />
                    <sapv:ExpressionTextBox Grid.Row="1" Grid.Column="1" x:Uid="configNameBox" x:Name="configNameBox"
                                MaxLines="2" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.ConnectionString, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type s:String}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />

                    <!-- ModelItem.ProviderName -->
                    <TextBlock Grid.Row="2" Text="Provider name:" />
                    <sapv:ExpressionTextBox Grid.Row="2" Grid.Column="1" x:Uid="providerNameBox" x:Name="providerNameBox"
                                MaxLines="1" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.ProviderName, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type s:String}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />

                    <!-- ModelItem.ConnectionString -->
                    <TextBlock Grid.Row="3" Text="Connection string:" />
                    <sapv:ExpressionTextBox Grid.Row="3" Grid.Column="1" x:Uid="connectionStringBox" x:Name="connectionStringBox"
                                MaxLines="1" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.ConnectionString, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type s:String}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />

                    <!-- ModelItem.CommandType -->
                    <TextBlock Grid.Row="4" Text="Command type:" />
                    <sapv:ExpressionTextBox Grid.Row="4" Grid.Column="1" x:Uid="commandTypeBox" x:Name="commandTypeBox"
                                MaxLines="1" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.CommandType, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type sd:CommandType}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />
                    
                    <!-- ModelItem.Parameters -->
                    <TextBlock Grid.Row="5" Text="Parameters:" />
                    <DataGrid Grid.Row="5" Grid.Column="1" x:Name="DataGrid_1" Margin="7,0,0,0" CanUserAddRows="True" ItemsSource="{Binding Path=ModelItem.Parameters}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Name" Binding="{Binding Path=Key}" />
                            <DataGridTemplateColumn Header="Value">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <sapv:ExpressionTextBox Expression="{Binding Path=Value, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                            ExpressionType="{x:Type sd:CommandType}"
                                            OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                        
                    </DataGrid>
                    
                    <!--
                    <sapv:ExpressionTextBox Grid.Row="4" Grid.Column="1" x:Uid="parametersBox" x:Name="parametersBox"
                                MaxLines="1" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.Parameters, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" />
                    -->
                    
                    <!-- ModelItem.Sql -->
                    <TextBlock Grid.Row="6" Text="Sql:" />
                    <sapv:ExpressionTextBox Grid.Row="6" Grid.Column="1" x:Uid="sqlBox" x:Name="sqlBox" Margin="7,0,0,0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                Expression="{Binding Path=ModelItem.Sql, Mode=TwoWay, Converter={StaticResource argumentToExpressionConverter}, ConverterParameter=In}"
                                ExpressionType="{x:Type sd:CommandType}"
                                OwnerActivity="{Binding Path=ModelItem, Mode=OneWay}" MaxLines="255" />

                    <!-- Outputs Header -->
                    <TextBlock Grid.Row="7" Grid.ColumnSpan="2" x:Uid="Header_2" Text="Outputs(s):" FontWeight="Bold" Foreground="Navy" Margin="0,0,0,3" />
                </Grid>
            </StackPanel>
        </DataTemplate>

        <Style x:Uid="Style_1" x:Key="CollapsibleStyle" TargetType="{x:Type ContentPresenter}">
            <!--<Setter x:Uid="Setter_1" Property="ContentTemplate" Value="{DynamicResource CollapsedActivityViewTemplate}" />-->
            <Setter x:Uid="Setter_1" Property="ContentTemplate" Value="{DynamicResource ExpandedActivityViewTemplate}" />
            <Style.Triggers>
                <DataTrigger x:Uid="DataTrigger_1" Binding="{Binding Path=ShowExpanded}" Value="true">
                    <Setter x:Uid="Setter_2" Property="ContentTemplate" Value="{DynamicResource ExpandedActivityViewTemplate}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </sap:ActivityDesigner.Resources>
    <Grid>
        <ContentPresenter x:Uid="ContentPresenter_1" Style="{DynamicResource CollapsibleStyle}" Content="{Binding}" />
    </Grid>
</sap:ActivityDesigner>
